package com.zmn.oms.services.impl.conf.distribute;

import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.oms.model.entity.conf.distribute.DistributeWeightRelation;
import com.zmn.oms.model.entity.conf.distribute.DistributeWeightRelationQuery;
import com.zmn.oms.persistence.interfaces.conf.distribute.DistributeWeightRelationDao;
import com.zmn.oms.services.interfaces.conf.distribute.DistributeWeightRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述: 工程师派单权重关联配置基础接口实现类
 *
 * @author xujie
 * @since  2021-06-07 09:57:35
 **/
@Slf4j
@Service
public class DistributeWeightRelationServiceImpl implements DistributeWeightRelationService {

    private static final String TAG = "工程师派单权重关联配置基础服务接口";

    @Resource
    private DistributeWeightRelationDao distributeWeightRelationDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param relationId id
     * @author xujie
     * @since 2021-06-07 09:57:35
     **/
    @Override
    @ReadOnlyConnection
    public DistributeWeightRelation findById(Integer relationId) {

        Assert.notNull(relationId, TAG + "参数 relationId 不能为空");
        return distributeWeightRelationDao.findById(relationId);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author xujie
     * @since 2021-06-07 09:57:35
     **/
    @Override
    @ReadOnlyConnection
    public List<DistributeWeightRelation> listPageByQuery(DistributeWeightRelationQuery query) {

        Assert.notNull(query, TAG + "参数 query 不能为空");
        query.setTotalCount(distributeWeightRelationDao.countByQuery(query));
        return distributeWeightRelationDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author xujie
     * @since 2021-06-07 09:57:35
     **/
    @Override
    @ReadOnlyConnection
    public List<DistributeWeightRelation> listByQuery(DistributeWeightRelationQuery query) {

        Assert.notNull(query, TAG + "参数 query 不能为空");
        return distributeWeightRelationDao.listByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author xujie
     * @since 2021-06-07 09:57:35
     **/
    @Override
    @ReadOnlyConnection
    public Integer countByQuery(DistributeWeightRelationQuery query) {

        Assert.notNull(query, TAG + "参数 query 不能为空");
        return distributeWeightRelationDao.countByQuery(query);
    }

    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param distributeWeightRelation 待修改数据
     * @return java.lang.Integer
     * @author xujie
     * @since 2021-06-07 09:57:35
     **/
    @Override
    public Integer updateByKey(DistributeWeightRelation distributeWeightRelation) {

        Assert.notNull(distributeWeightRelation, TAG + "参数 distributeWeightRelation 不能为空");
        Assert.notNull(distributeWeightRelation.getRelationId(), TAG + "字段 relationId 不能为空");
        return distributeWeightRelationDao.updateByKey(distributeWeightRelation);
    }

    /**
     * 描述: 批量修改数据
     * @param distributeWeightRelationList 数据集合
     * @return java.lang.Integer 成功个数
     * @author xujie
     * @since  2021-06-07 09:57:35
     */
    @Override
    public Integer updateBatchByKey(List<DistributeWeightRelation> distributeWeightRelationList) {

        if (distributeWeightRelationList == null || distributeWeightRelationList.size() == 0) {
            return null;
        }
        return distributeWeightRelationDao.updateBatchByKey(distributeWeightRelationList);
    }

    /**
     * 描述: 新增数据
     *
     * @param distributeWeightRelation 待新增数据
     * @return java.lang.Integer 主键key
     * @author xujie
     * @since  2021-06-07 09:57:35
     **/
    @Override
    public Integer insert (DistributeWeightRelation distributeWeightRelation) {

        Assert.notNull(distributeWeightRelation, TAG + "参数 distributeWeightRelation 不能为空");
        return distributeWeightRelationDao.insert(distributeWeightRelation);
    }

    /**
     * 描述: 批量新增数据
     * @param distributeWeightRelationList 待新增数据集合
     * @return java.lang.Integer 成功个数
     * @author xujie
     * @since  2021-06-07 09:57:35
     */
    @Override
    public Integer insertBatch(List<DistributeWeightRelation> distributeWeightRelationList) {

        if (distributeWeightRelationList == null || distributeWeightRelationList.size() == 0) {
            return null;
        }
        return distributeWeightRelationDao.insertBatch(distributeWeightRelationList);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param relationId 主键
     * @return 执行结果码
     * @author xujie
     * @since 2021-06-07 09:57:35
     */
    @Override
    public Integer deleteByKey(Integer relationId) {

        Assert.notNull(relationId, TAG + "参数 relationId 不能为空");
        return distributeWeightRelationDao.deleteByKey(relationId);
    }

    /**
     * 描述: 根据主键批量删除数据
     *
     * @param relationIdList 待新增数据集合
     * @return java.lang.Integer 成功个数
     * @author xujie
     * @since  2021-06-07 09:57:35
     */
    @Override
    public Integer deleteBatchByKey(List<Integer> relationIdList) {

        if (relationIdList == null || relationIdList.size() == 0) {
            return null;
        }
        return distributeWeightRelationDao.deleteBatchByKey(relationIdList);
    }

}